package com.example.ftp.Controller.SiteManage;

import com.example.ftp.Controller.MainWindow.FileList.FileItemContextMenuItem;
import com.example.ftp.Controller.MainWindow.MainWindow;
import javafx.scene.control.ContextMenu;
import javafx.scene.control.MenuItem;
import javafx.scene.control.TextInputDialog;
import javafx.stage.Stage;

import java.io.IOException;
import java.util.Optional;

public class SiteItemContextMenu extends ContextMenu {
    public SiteItemContextMenu() {
        MenuItem connectItem = new MenuItem("Connect");
        MenuItem deleteItem = new MenuItem("Delete");
        MenuItem detailItem = new MenuItem("Detail");

        getItems().add(connectItem);
        getItems().add(deleteItem);
        getItems().add(detailItem);


        connectItem.setOnAction(e-> {
            MainWindow.getControllerInstance().connectSite(SiteList.getSelectedSite());
            Stage s = (Stage) SiteList.getControllerInstance().getSiteTable().getScene().getWindow();
            s.close();
        });

        deleteItem.setOnAction(e -> {
            try {
                SiteList.getControllerInstance().delSite();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        });

        detailItem.setOnAction(e -> {
            SiteInfo s = new SiteInfo();
            try {
                s.open(SiteList.getSelectedSite());
                SiteList.getControllerInstance().refreshList();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
        });
    }
}
